package cn.vivi.recyclercomp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;

/**
 * Activity定义了许多的状态，用户可以通过set(status)来切换状态，每个状态对应一个View，用户还可以自定义这个View
 * 
 * 每个状态对应一个UI 布局， 用户可以自定义这些布局通过setXX方法（e.g setEmptyView）
 * 
 * @author Vivi Peng
 * 
 */
public abstract class StatusActivity extends AppCompatActivity implements IComponentStatus {

	private static final String KEY_ID = "key_id";
	private String mId;

	private RelativeLayout mContentView;
	private StatusHelper mHelper;
	private Status mStatus = Status.EMPTY;
	private Toolbar mToolbar;


	public StatusActivity() {
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_status);
		mToolbar = (Toolbar )findViewById(R.id.toolbar);
		setSupportActionBar(mToolbar);
		mToolbar.setNavigationOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		mContentView = (RelativeLayout) findViewById(R.id.rlytContent);
		mHelper = new StatusHelper(this, mContentView);

		View newContentView = createDataContentView(getLayoutInflater(), null, savedInstanceState);
		mHelper.setDataContentView(newContentView);
		mHelper.changeStatus(mStatus);
  
	}
	
	
	public Toolbar getToolbar() {
		return mToolbar;
	}


	/**
	 * 请确保在onCreateView之后调用
	 * 
	 * @param status
	 */
	public void setStatus(Status status) {
		if (mStatus != status) {
			mStatus = status;
			mHelper.changeStatus(mStatus);
		}
	}


	public Status getStatus() {
		return mStatus;
	}


	public void setDataContentView(View contentView) {
		mHelper.setDataContentView(contentView);
	}


	public void setEmptyView(View emptyView) {
		mHelper.setEmptyView(emptyView);
	}


	public void setEmptyInvalidNetView(View view) {
		mHelper.setEmptyInvalidNetView(view);
	}


	public void setEmptyRefreshing(View view) {
		mHelper.setEmptyRefreshing(view);
	}


	public void setEmptyErrorView(View view) {
		mHelper.setEmptyErrorView(view);
	}


	public View getEmptyView() {
		return mHelper.getEmptyView();
	}


	public View getDataContentView() {
		return mHelper.getDataContentView();
	}


	public View getEmptyRefreshingView() {
		return mHelper.getEmptyRefreshingView();
	}


	public View getEmptyInvalidNetView() {
		return mHelper.getEmptyInvalidNetView();
	}


	public View getEmptyErrorView() {
		return mHelper.getEmptyErrorView();
	}

}
